<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('课程包列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>

                        <li>
                            <label>名称：</label>
                            <input type="text" name="name"/>
                            <input id="parentId" name="parentId" type="hidden" th:value="${id}">
                        </li>

                        <li>
                            <label>价格：</label>
                            <input type="text" name="price"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <input type="file" name="upload" id="upload" style="display: none;"/>
        <input type="hidden" name="id" id="id" style="display: none;"/>
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="addParent()">
                <i class="fa fa-plus"></i> 添加周
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" >
                <i class="fa fa-remove"></i> 删除
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "system/package";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            importUrl: prefix + "/importData",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "课程包",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '周Id',
                },

                {
                    field: 'name',
                    title: '名称'
                },
                {
                    field: 'orderNum',
                    title: '排序'
                },
                {
                    field: 'createdName',
                    title: '创建人'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs  " href="javascript:void(0)" onclick="editWeek(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-warning btn-xs  " href="javascript:void(0)" onclick="timeContentList(\'' + row.id + '\')"></i>详情</a> ');
                        actions.push('<a class="btn btn-success btn-xs  " href="javascript:void(0)" onclick="course(\'' + row.id + '\')"></i>课程列表</a> ');
                        actions.push('<a class="btn btn-warning btn-xs  " href="javascript:void(0)" onclick="copyWeek(\'' + row.id + '\')"></i>拷贝周详情</a> ');
                        actions.push('<a class="btn btn-warning btn-xs  " href="javascript:void(0)" onclick="copyWeekCourse(\'' + row.id + '\')"></i>拷贝周课程</a> ');
                        actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function addMarkdown(id, type) {
        var href = ctx + 'system/courseContent/addMarkdown?id=' + id + '&type=' + type;
        $.modal.open("文本编辑", href);
    }

    function onFile(id) {
        $('#id').val(id);
        $('#upload').click();
    }
    function course(id) {
        var url = ' /system/course?id=' + id;
        $.modal.openTab("课程 - 列表", url);
    }


    function addParent() {
        var parentId = $('#parentId').val();
        var url = prefix + '/addParent?id=' + parentId;
        $.modal.open("添加周", url);
    }

    function timeContentList(id) {
        var url = '/system/courseContent/coursePackageList?packageId=' + id;
        $.modal.openTab("周 - 详情", url);
    }


    $('#upload').on('change', function () {
        var farmdate = new FormData();
        farmdate.append("file", $('#upload')[0].files[0]);
        farmdate.append("id", $('#id').val());
        $.ajax({
            type: "post",
            url: prefix + "/importData",
            data: farmdate,
            contentType: false,
            processData: false,
            success: function (date) {
                $.modal.alertSuccess("添加成功")
                $.table.refresh();
            }
        })
    });
    function copyWeek(id) {
        var url = prefix + '/copyWeekPackages?id=' + id;
        $.modal.open("选择需要拷贝到的课程包", url);
    }
    function editWeek(id) {
        var url = prefix + '/editWeek/' + id;
        $.modal.open("修改周名称", url);
    }
    function copyWeekCourse(id) {
        var url = prefix + '/copyWeekCoursePackages?id=' + id;
        $.modal.open("选择需要拷贝到的周", url);
    }

</script>

</body>
</html>